"""
启动类
"""
import os, sys
import uvicorn
from fastapi import FastAPI, HTTPException, Request
from logger.logger import logger
from contextlib import asynccontextmanager
import config.mongodb

@asynccontextmanager
async def lifespan(app: FastAPI):
    logger.info("程序启动")
    yield

app = FastAPI(lifespan=lifespan, title="画机")

@app.exception_handler(Exception)
async def global_exception_handler(request, exc):
    # 记录异常日志
    logger.error(f"全局异常处理: {str(exc)}", exc_info=True)
    # 直接返回HTTPException响应
    return HTTPException(status_code=500, detail="服务器内部错误")


if __name__ == '__main__':
    uvicorn.run(app, host="0.0.0.0", port=8077, log_level="info")